package outbound.load.dataObjects
{
	import common.utils.DateManager;
	
	import mx.collections.ArrayCollection;
	
	[Bindable]
	public class ShippingLoadDO
	{
		public var INTERNAL_LOAD_NUM:String = "0";
		public var WAREHOUSE:String = "";
		public var TRAILING_STS:String = "100";
		public var LEADING_STS:String = "100";
		public var CARRIER:String = "";
		public var SCHEDULED_SHIP_DATE:String = DateManager.GetTodayString();
		public var ACTUAL_SHIP_DATE:String = DateManager.GetTodayString();
		public var LOAD_SIZE_DEF:String = "";
		public var LOAD_CLOSED:String = "N";
		public var SEAL_ID:String = "";
		public var TRAILER_ID:String = "";
		public var TOTAL_SHIPMENTS:String = "0";
		public var TOTAL_CONTAINERS:String = "0";
		public var TOTAL_WEIGHT:String = "0";
		public var WEIGHT_UM:String = "";
		public var TOTAL_VOLUME:String = "0";
		public var VOLUME_UM:String = "";
		public var USER_STAMP:String = "";
		public var DATE_TIME_STAMP:String = DateManager.GetTodayString();
		public var ROUTE:String = "";
		public var DOCK_DOOR:String = "";
		public var DRIVER:String = "";
		public var MAX_WEIGHT:String = "0";
		public var MAX_VOLUME:String = "0";
		public var WEIGHT_PERCENT:String = "0/0";
		public var VOLUME_PERCENT:String = "0/0";

		public function ShippingLoadDO()
		{
		}

		public function Init(xmlObj:XML):void
		{			
			if(null == xmlObj)
				return;
			else{
				for each (var itemProp:XML in xmlObj.children()) {
					//Use XML node name to reference matching property in value object				
					this[itemProp.name()] = itemProp;
				}
			}
			this.WEIGHT_PERCENT = TOTAL_WEIGHT + "/" + MAX_WEIGHT;
			this.VOLUME_PERCENT = TOTAL_VOLUME + "/" + MAX_VOLUME;
		}

		public function ToXML():XML{
			var xmlObj:XML = 
				<SHIPPING_LOAD>
					<INTERNAL_LOAD_NUM>{INTERNAL_LOAD_NUM}</INTERNAL_LOAD_NUM>
					<WAREHOUSE>{WAREHOUSE}</WAREHOUSE>
					<LEADING_STS>{LEADING_STS}</LEADING_STS>
					<TRAILING_STS>{TRAILING_STS}</TRAILING_STS>
					<CARRIER>{CARRIER}</CARRIER>
					<SCHEDULED_SHIP_DATE>{SCHEDULED_SHIP_DATE}</SCHEDULED_SHIP_DATE>
					<ACTUAL_SHIP_DATE>{ACTUAL_SHIP_DATE}</ACTUAL_SHIP_DATE>
					<LOAD_SIZE_DEF>{LOAD_SIZE_DEF}</LOAD_SIZE_DEF>
					<LOAD_CLOSED>{LOAD_CLOSED}</LOAD_CLOSED>
					<SEAL_ID>{SEAL_ID}</SEAL_ID>
					<TRAILER_ID>{TRAILER_ID}</TRAILER_ID>
					<TOTAL_SHIPMENTS>{TOTAL_SHIPMENTS}</TOTAL_SHIPMENTS>
					<TOTAL_CONTAINERS>{TOTAL_CONTAINERS}</TOTAL_CONTAINERS>
					<TOTAL_WEIGHT>{TOTAL_WEIGHT}</TOTAL_WEIGHT>
					<WEIGHT_UM>{WEIGHT_UM}</WEIGHT_UM>
					<TOTAL_VOLUME>{TOTAL_VOLUME}</TOTAL_VOLUME>
					<VOLUME_UM>{VOLUME_UM}</VOLUME_UM>
					<USER_STAMP>{USER_STAMP}</USER_STAMP>
					<DATE_TIME_STAMP>{DATE_TIME_STAMP}</DATE_TIME_STAMP>
					<ROUTE>{ROUTE}</ROUTE>
					<DOCK_DOOR>{DOCK_DOOR}</DOCK_DOOR>
					<DRIVER>{DRIVER}</DRIVER>
				</SHIPPING_LOAD>;
				
			return xmlObj;			
		}
		

		public static function getShippingLoad(list:XMLList):ArrayCollection
		{
			var ac:ArrayCollection = new ArrayCollection();
			for each(var xml:XML in list)
			{
				var shpLoad:ShippingLoadDO = new ShippingLoadDO();
				shpLoad.Init(xml);
				ac.addItem(shpLoad);
			}
			return ac;
		}	
	}
}